package com.hy.servlet;

import com.hy.dao.StudentDAO;
import com.hy.model.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yoka24443 on 2018-4-24.
 */
public class UpdateStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        boolean isSuccess;
        StudentDAO dao = new StudentDAO();
        Student model = new Student();

        model.setStudentNO(request.getParameter("studentNO"));
        model.setRealName(request.getParameter("realName"));
        model.setClassName(request.getParameter("className"));
        model.setAge(Integer.parseInt(request.getParameter("age")));
        model.setTel(request.getParameter("tel"));
        model.setAddress(request.getParameter("address"));
        model.setQq(request.getParameter("qq"));
        model.setWechat(request.getParameter("wechat"));

        isSuccess = dao.update(model);

        if (isSuccess) {
            response.getWriter().print("update is successful!");
        } else {
            response.getWriter().print("update is failed!");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
